import os
from os.path import join

def location(path, searchfile):
    i = 100
    print(i*3)

    a = 'asdsdf'
    print(a)

    try:
        fileList = os.listdir(path)  # 获取path中包含的文件
        # print(fileList)
        if searchfile in fileList:  # 判断文件是否在fileList
            completePath = join(path, searchfile)  # 文件存在则拼接成完整路径
            print("目标路径为:", completePath)  # 输出文件完整路径

            return completePath
        else:  # 文件不存在则返回"无效路径"
            print("无效路径!")

    except FileNotFoundError:  # 抛出异常:找不到文件
        print("FileNotFoundError!系统找不到指定的路径!", path, searchfile)
        location(input("请输入目标根目录:"), input("请输入目标文件名:"))
    except OSError:  # 抛出异常:
        print("OSError!错误的写法!")
        location(input("请输入目标根目录:"), input("请输入目标文件名:"))




if __name__ == '__main__':


    path = input("请输入目标根目录:")
    searchfile = input("请输入目标文件名:")
    complete_path = location(path, searchfile)
    print(complete_path)



    # location(input("请输入目标根目录:"), input("请输入目标文件名:"))
    #
    # flag = True
    # while flag:
    #     answer = input("是否继续输入？(y/n)")
    #     if answer == "y":
    #         location(input("请输入目标根目录:"), input("请输入目标文件名:"))
    #     else:
    #         print("已退出While循环程序!")
    #         flag = False

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
